const app = getApp()
Page({
  data: {
    adminAccount: '',
    adminPsw: '',
  },

  submitBtnClick: function(e) {
    // console.log(this.data.adminAccount)
    // console.log(this.data.adminPsw)
    let my_this = this;
    const db = wx.cloud.database()
    if (this.data.adminAccount == 'admin' & this.data.adminPsw=='admin')
    {
      wx.redirectTo({
        url: '../../admin_manage/admin_manage'
      })}
      else{
    db.collection('Admin').where({
        AD_ID: my_this.data.adminAccount
      })
      .get({
        success(res) {
          if (res.data.length == 0) {
            wx.showModal({
              title: '登陆失败',
              content: '用户不存在',
              showCancel: false
            })
          } else if (my_this.data.adminPsw == res.data[0].PW) {
            wx.redirectTo({
              url: 'order_admin?city='+res.data[0].city
            })
          } else {
            wx.showModal({
              title: '登陆失败',
              content: '密码错误',
              showCancel: false
            })
          }
        }
        })
    }
  },



  inputAccount: function(e) {
    this.setData({
      adminAccount: e.detail.value,
    })
  },

  inputPsw: function(e) {
    this.setData({
      adminPsw: e.detail.value
    })
  },

})